package esb.chapter5.camel.router;

import static org.apache.camel.builder.xml.XPathBuilder.xpath;

import javax.xml.transform.dom.DOMSource;

import org.apache.camel.builder.RouteBuilder;

public class InsuranceRouter extends RouteBuilder {
	
	private final static String NAMESPACE = "http://esbinaction.com/insurance";
	private final static String SERVICE_IN = "jbi:service:" + 
		NAMESPACE + "/insuranceDSLRouter";
	private final static String CAR_OUT = "jbi:service:" + 
		NAMESPACE + "/carAppInDSL";
	private final static String TRAVEL_OUT = "jbi:service:" + 
		NAMESPACE + "/travelAppInDSL";
	
	public void configure() {
		from(SERVICE_IN)
			.convertBodyTo(DOMSource.class)
			.choice()
				.when(xpath("//ins:insurance-type='Car'").namespace("ins", "http://insurance.com"))
					.to(CAR_OUT)
				.otherwise()
					.to(TRAVEL_OUT);
	}

}
